﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Fotobanka
{
    public partial class UkazGalerie : System.Web.UI.Page
    {
        GalleriesManager gm;
        protected void Page_Load(object sender, EventArgs e)
        {
            gm = new GalleriesManager();
            if (!IsPostBack)
            {
                LoginInfo li = (LoginInfo)HttpContext.Current.Session["logged_user_id"];
                if (li != null)
                {
                    List<GalleryObject> l;
                    //pokud je to admin, vyberu pro nej vsechny galerie
                    if (li.Role == Utils.SystemRoles.Admin)
                    {
                        l = gm.SelectAllGalleries();
                    }
                    else {
                        l = gm.SelectAssignedGalleriesForUser(li);
                    }
                    
                    galerie_rep.DataSource = l;
                    galerie_rep.DataBind();
                    Label1.Text = "Nalezeno galerii: " + l.Count;
                }
                else {
                    Label1.Text = "Chyba id";
                }
            } 
        }

        protected void emailSearchButton_Click(object sender, EventArgs e)
        {
            LoginInfo li = (LoginInfo)HttpContext.Current.Session["logged_user_id"];
            if (li != null)
            {
                List<GalleryObject> l;
                
                if (li.Role == Utils.SystemRoles.Admin)
                {
                    l = gm.SearchGalleriesViaEmailForAdmin(emailSearch.Text);
                }
                else
                {
                    l = gm.SearchGalleriesViaEmailForNoAdmin(emailSearch.Text);
                }

                galerie_rep.DataSource = l;
                galerie_rep.DataBind();
                Label1.Text = "Nalezeno galerii: " + l.Count;
            }
            else
            {
                Label1.Text = "Chyba id";
            }
        }

        protected void descSearchButton_Click(object sender, EventArgs e)
        {
            LoginInfo li = (LoginInfo)HttpContext.Current.Session["logged_user_id"];
            if (li != null)
            {
                List<GalleryObject> l;

                if (li.Role == Utils.SystemRoles.Admin)
                {
                    l = gm.SearchGalleriesViaDescriptionForAdmin(descSearch.Text);
                }
                else
                {
                    l = gm.SearchGalleriesViaDescriptionForNoAdmin(descSearch.Text);
                }

                galerie_rep.DataSource = l;
                galerie_rep.DataBind();
                Label1.Text = "Nalezeno galerii: " + l.Count;
            }
            else
            {
                Label1.Text = "Chyba id";
            }
        }
    }
}
